package com.mo.axion.common.pipeline;

import com.mo.axion.common.enums.RespStatusEnum;

import java.util.Objects;

/**
 * @author Mo
 * @createTime 2024/2/1 16:58
 * @description 责任链异常类
 */
public class ProcessException extends RuntimeException{
    /**
     * 流程处理上下文
     */
    private final ProcessContext processContext;

    public ProcessException(ProcessContext processContext) {
        this.processContext = processContext;
    }
    public ProcessException(ProcessContext processContext, Throwable cause) {
        super(cause);
        this.processContext = processContext;
    }

    /**
     * Returns the detail message string of this throwable.
     *
     * @return the detail message string of this {@code Throwable} instance
     * (which may be {@code null}).
     */
    @Override
    public String getMessage() {
        if (Objects.nonNull(this.processContext)) {
            return this.processContext.getResponse().getMsg();
        }
        return RespStatusEnum.CONTEXT_IS_NULL.getMsg();
    }
    public ProcessContext getProcessContext() {
        return processContext;
    }
}
